package com.xubeizhi.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 跨域
 * @author mi
 * @create 2023/4/13 14:54
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {
    public void addCorsMappings(CorsRegistry corsRegistry) {
/*        //设置允许跨域的路径
        corsRegistry.addMapping("/**")
                //设置允许跨域请求的域名
                .allowedOriginPatterns("www.xubeizhi.cn")
                //是否允许证书
                .allowCredentials(false)
                //设置允许证书的方法
                .allowedMethods("GET","POST")
                //设置允许的header属性
                .allowedHeaders()
                //允许跨域的时间
                .maxAge(3600);
    }*/
        corsRegistry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }
}
